package com.common.dao;



import com.common.entity.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @classDescription:
 * @author:xiayingjie
 * @createTime:15/8/9
 */

public interface UserDAO extends BaseDAO<User,Integer> {

    /**
     * 根据用户名查询用户
     * @param loginName
     * @return
     */
    public User findByLoginName(String loginName);

    /**
     * 根据昵称查询用户
     * @param nickName
     * @return
     */
    public User findByNickName(String nickName);

    /**
     * 根据令牌查询用户
     * @param accessTocken
     * @return
     */
    public User findByAccessToken(String accessTocken);

    /**
     * 第三方登陆
     * @param thirdNo
     * @param registerSource
     * @return
     */
    public User findByThirdNoAndRegisterSource(String thirdNo, int registerSource);
    /**
     * 第三方登陆
     * @param thirdNo
     * @return
     */
    public User findByThirdNo(String thirdNo);

    @Modifying
    @Query("update User  u set u.followCount=u.followCount-1 where u.id=?1")
    public int reduceFollowCount(int userId);

    @Modifying
    @Query("update User  u set u.followCount=u.followCount+1 where u.id=?1")
    public int addFollowCount(int userId);

    @Modifying
    @Query("update User  u set u.fansCount=u.fansCount-1 where u.id=?1")
    public int reduceFansCount(int userId);

    @Modifying
    @Query("update User  u set u.fansCount=u.fansCount+1 where u.id=?1")
    public int addFansCount(int userId);

}
